local autofly = false
local turretmode = false
local lastpressed1 = false
local lastpressed2 = false

function keywaspressedfly()
	if autofly then
		autofly = false
		LocalPlayer( ):ConCommand( "Flymode false \n" )
	else
		autofly = true
		LocalPlayer( ):ConCommand( "Flymode true \n" )
	end
end

function BGprint() 
	if LocalPlayer():KeyDown(IN_SPEED) then
		lastpressed1 = true
	else	
		if lastpressed1 then
			lastpressed1 = false
			keywaspressedfly()
			Msg("Flymode")
		end
	end
	
	if LocalPlayer():KeyDown(8192) then
		lastpressed2 = true
	else	
		if lastpressed2 then
			lastpressed2 = false
			turretmodefunction()
		end
	end
	if (autofly && not LocalPlayer( ).InVehicle2) then
		autofly = false
		LocalPlayer( ):ConCommand( "Flymode false \n" )
	end
end 
hook.Add("Tick", "BGprint", BGprint)

function turretmodefunction()
	if turretmode then
		turretmode = false
		LocalPlayer( ):ConCommand( "Turretmode false \n" )
	else
		turretmode = true
		LocalPlayer( ):ConCommand( "Turretmode true \n" )
	end
end

